
//
// 120128 - AH - (Garage) Created, based on MineConversationComponent.
//

package org.soekrat.gui.swing.chat.objectconversation;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JLabel;

import org.soekrat.AttributeObject;
import org.soekrat.engine.Soekrat2Engine;
import org.soekrat.engine.mine.Mine;
import org.soekrat.engine.ontology.ptable.Product;
import org.soekrat.engine.pit.Pit;
import org.soekrat.gui.swing.chat.objectconversation.note.NoteMarkLabel;

/**
 * <p>
 *   {@link ConversationComponent} for 
 *   {@link Mine} ontology retrieved content.
 * </p>
 * @author Arne Halvorsen (AH)
 * @author Laetitia Le Chatton (LLC) 
 */
@SuppressWarnings("serial")
public final class ProductTableConversationComponent 
  extends ConversationComponent
{
  /**
   * <p>
   *   Constructor.
   * </p>
   * @param engine {@link Soekrat2Engine}.
   * @param res    Retrieved.
   */
  public ProductTableConversationComponent(Soekrat2Engine engine, 
    List<AttributeObject> res)
  {
    super(engine, "product-table");
    
    setLayout(new FlowLayout(FlowLayout.LEFT));
    
    Box column=new Box(BoxLayout.Y_AXIS);
    
    for (AttributeObject product : res) 
    {
      String name=((Product)product).getSoekratName().getPure();
      
      Pit pit=m_engine.getPit();
      
      String ontology=getOntology();
      
      if (pit.hasContent(name, ontology) && !isPureNote(name))
      {  
        final JButton button=new JButton(name);
        button.setName(name);
        add(button);

        button.addActionListener
        (
          new ActionListener() 
          {
            public void actionPerformed(ActionEvent e) 
            {
              showContent(button.getName());
            }
          }
        );
      }
      else
      {
        add(new JLabel(name));
      }
      
      add(new NoteMarkLabel(name, this));
    }
    
    add(column, BorderLayout.CENTER);
  }
  
}
